package lx5;

import java.util.Random;

public class RedPack extends Thread{
    private static int sum = 100,cnt = 1;
    private static Random r = new Random();
    private static final Object lo  = new Object();

    @Override
    public void run() {
        synchronized (lo) {
            if (cnt <= 3) {
                int t = 0;
                if (cnt == 1 || cnt == 2) t = r.nextInt(sum);
                else t = sum;
                sum -= t;
                System.out.println(this.getName() + "    抢到了" + t + "元");
            } else {
                System.out.println(this.getName() + "    没抢到");
            }
            cnt++;
        }
    }
}
